unit Forms.LoginForm;

interface

uses
  Winapi.Windows, Winapi.Messages,
  System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  Vcl.Buttons, Vcl.ExtCtrls, Vcl.ComCtrls,
  TextEdit, ComboEdit;

type
  TLoginForm = class(TForm)
    btnAcessar: TBitBtn;
    btnCancelar: TBitBtn;
    pcAcesso: TPageControl;
    tabAcesso: TTabSheet;
    tabConfig: TTabSheet;
    panAcesso: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    txtUsername: TTextEdit;
    txtPassword: TTextEdit;
    panConfig: TPanel;
    Label3: TLabel;
    txtDatabase: TTextEdit;
    SpeedButton1: TSpeedButton;
    ComboEdit1: TComboEdit;
    cmbTipoAcesso: TLabel;
    procedure btnCancelarClick(Sender: TObject);
    procedure btnAcessarClick(Sender: TObject);
  private
    FResult: ^boolean;
  public
    class function ValidarAcesso: boolean;
  end;

implementation

{$R *.dfm}

uses
  Controllers.SessionController;

{ TLoginForm }

class function TLoginForm.ValidarAcesso: boolean;
var
  form: TLoginForm;
begin
  result := false;
  form := TLoginForm.Create(nil);
  try
    form.FResult := @result;
    form.ShowModal;
  finally
    form.Free;
  end;
end;

procedure TLoginForm.btnAcessarClick(Sender: TObject);
begin
  FResult^ := SessionController.ValidUserAndLoad(txtUsername.Text, txtPassword.Text);
  if FResult^ then
    begin
      Close;
    end
  else
    begin

    end;
end;

procedure TLoginForm.btnCancelarClick(Sender: TObject);
begin
  Close;
end;

end.
